package com.lgt_enterprise_android.utils;

import android.content.Context;
import android.content.SharedPreferences;


public class PrefBigDataUtils {

    public static final String SHARED_PREF_NAME = "lgt_b_big_data";

    public static  final String COMPANY_INFO="company_info";
    public static  final String PERSONAL_INFO="personal_info";
    /**
     * Save string value to preference
     *
     * @param context
     * @param key
     * @param value
     */
    public static void setSharedPrefStringData(Context context, String key, String value) {
        if (context == null || key == null)
            return;
        SharedPreferences appInstallInfoSharedPref = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor appInstallInfoEditor = appInstallInfoSharedPref.edit();
        appInstallInfoEditor.putString(key, value);
        appInstallInfoEditor.apply();
    }


    /**
     * Get boolean value from preference
     *
     * @param context
     * @param key
     * @return
     */
    public static boolean getSharedPrefBoolean(Context context, String key) {
        if (context == null || key == null)
            return false;
        SharedPreferences userAcountPreference = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
        return userAcountPreference.getBoolean(key, false);
    }


    public static void cleanAlldata(Context context) {
        if (context == null)
            return;
        SharedPreferences appInstallInfoSharedPref = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor appInstallInfoEditor = appInstallInfoSharedPref.edit();
        appInstallInfoEditor.clear();
        appInstallInfoEditor.apply();
    }

    /**
     * Get string value from preference
     *
     * @param context
     * @param key
     * @return
     */
    public static String getSharedPrefString(Context context, String key) {
        if (context == null || key == null)
            return "";
        SharedPreferences userAcountPreference = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
        if (userAcountPreference.getString(key, "").isEmpty()) {
            return "";
        }
        return userAcountPreference.getString(key, "");
    }


    /**
     * @param context
     * @param key
     * @return
     */
    public static float getSharedPrefFloat(Context context, String key) {
        if (context == null || key == null)
            return 0.0f;
        SharedPreferences userAcountPreference = context.getSharedPreferences(SHARED_PREF_NAME,
                Context.MODE_PRIVATE);

        return userAcountPreference.getFloat(key, 0);
    }


    /**
     * Get int value from preference
     *
     * @param context
     * @param key
     * @return
     */
    public static int getSharedPrefInt(Context context, String key) {
        if (context == null || key == null)
            return 0;
        SharedPreferences userAcountPreference = context.getSharedPreferences(SHARED_PREF_NAME,
                Context.MODE_PRIVATE);

        return userAcountPreference.getInt(key, 0);
    }

    /**
     * save boolean value to preference
     *
     * @param context
     * @param key
     * @param value
     */
    public static void setSharedPrefBooleanData(Context context, String key, boolean value) {
        if (context == null || key == null)
            return;
        SharedPreferences appInstallInfoSharedPref = context.getSharedPreferences(SHARED_PREF_NAME,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor appInstallInfoEditor = appInstallInfoSharedPref.edit();
        appInstallInfoEditor.putBoolean(key, value);
        appInstallInfoEditor.apply();
    }

    /**
     * Save float value to preference
     *
     * @param context
     * @param key
     * @param value
     */
    public static void setSharedPrefFloatData(Context context, String key, float value) {
        if (context == null || key == null)
            return;
        SharedPreferences appInstallInfoSharedPref = context.getSharedPreferences(SHARED_PREF_NAME,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor appInstallInfoEditor = appInstallInfoSharedPref.edit();
        appInstallInfoEditor.putFloat(key, value);
        appInstallInfoEditor.apply();
    }

    /**
     * Save int value to preference
     *
     * @param context
     * @param key
     * @param value
     */
    public static void setSharedPrefIntData(Context context, String key, int value) {
        if (context == null || key == null)
            return;
        SharedPreferences appInstallInfoSharedPref = context.getSharedPreferences(SHARED_PREF_NAME,Context.MODE_PRIVATE);
        SharedPreferences.Editor appInstallInfoEditor = appInstallInfoSharedPref.edit();
        appInstallInfoEditor.putInt(key, value);
        appInstallInfoEditor.apply();
    }


}
